<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>NovaCube - Login</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<!-- Latest compiled and minified CSS -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
	<!-- Optional theme -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
	<!-- Font awesome pour les icones -->
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
	
</head>

<body style="background-image: url('fond.png');background-repeat: no-repeat;background-attachment: fixed;background-position: center;">

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="">NovaCube</a>
    </div>

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a href="index.php"><i class="fa fa-home"></i> Accueil</a></li>
        <li><a href="http://novacube.fr/forums"><i class="fa fa-comments"></i> Forum</a></li>
      </ul>
    </div>
  </div>
</nav>

<div class="container-fluid">
<div class="row">
  <div class="col-md-1">
  </div>
  <div class="col-md-10">
    <div class="panel panel-default">
        <div class="panel-heading"><b><i>Connexion au panel de rédaction:</i></b></div>
        <div class="panel-body">
          <form method="post" action="login.php" class="form-horizontal">
          <div class="form-group">
            <label class="col-sm-2 control-label">Pseudo:</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="pseudo" placeholder="Pseudo">
            </div>
          </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">Mot de passe:</label>
        <div class="col-sm-10">
          <input type="password" class="form-control" name="password" placeholder="Mot de passe" width="20%">
          <h5><small>« Avis aux rédacteurs: réclamez votre pseudo et mot de passe à Lioche ! »</small></h5>
        </div>
      </div>

      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <button name="submit"type="submit" class="btn btn-default" href="#">Connexion</button>
        </div>
      </div>
          </form>
        </div>
        </div>
    </div>
    <div class="col-md-1">
    </div>

  </div>
</div>

<?php
include("bdd.php");


if(isset($_POST['submit'])){
	$pseudo = strtolower(htmlspecialchars(trim($_POST['pseudo'])));
	$password = htmlspecialchars(trim($_POST['password']));

  if(empty($pseudo)){
    ?>
    <center>
        <div class="col-md-3"></div>
        <div class="col-md-6">
          <div class="alert alert-danger" role="alert">
            <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            <span class="sr-only">Error:</span>
            <b>Veuillez indiquer votre pseudo !</b>
          </div>
        </div>
        </center>
    <?php
  }else if(empty($password)){
    ?>
    <center>
        <div class="col-md-3"></div>
        <div class="col-md-6">
          <div class="alert alert-danger" role="alert">
            <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            <span class="sr-only">Error:</span>
            <b>Veuillez indiquer votre mot de passe !</b>
          </div>
        </div>
        </center>
    <?php
  }else{
          
  $password = md5($password);
  
  $log = mysqli_query($connexion, "SELECT * FROM users WHERE username = '$pseudo' AND password = '$password'");
  $rows = mysqli_num_rows($log);

  if($rows == 1){
    session_start();
    $_SESSION['pseudo'] = $pseudo;

    header("Location:panel.php");
  }else{
  ?>
    <center>
        <div class="col-md-3"></div>
        <div class="col-md-6">
          <div class="alert alert-danger" role="alert">
            <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            <span class="sr-only">Error:</span>
            <b>Nom d'utilisateur ou mot de passe incorrect !</b>
          </div>
        </div>
    </center>
  <?php
  }

}

}

?>
</body>
</html>